<template>
  <div class="index">
    <el-container>
      <el-header height="68px">
        <m-header></m-header>
      </el-header>
      <el-container>
        <el-aside width="200px">
          <m-aside></m-aside>
        </el-aside>
        <el-main>
          <div class="main">
            <div class="header-top">
              <el-breadcrumb separator-class="el-icon-arrow-right">
                <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                <el-breadcrumb-item>明细查询</el-breadcrumb-item>
                <el-breadcrumb-item>资金明细</el-breadcrumb-item>
              </el-breadcrumb>
              <h2 class="title">资金明细</h2>
            </div>
            <div class="row">
              <el-form :inline="true" :model="formInline"  class="demo-form-inline">
                <div class="water">

                  <span class="waterTime">流水时间：</span>
                  <el-date-picker
                    v-model="formInline.time"
                    type="daterange"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期">
                  </el-date-picker>
                </div>
                <el-form-item label="资金类型：">
                  <el-select v-model="formInline.status" placeholder="请选择">
                    <el-option label="全部" value=""></el-option>
                    <el-option label="新人红包" value="0"></el-option>
                    <el-option label="定时红包" value="1"></el-option>
                    <el-option label="转发红包" value="2"></el-option>
                    <el-option label="瓜分红包" value="3"></el-option>
                    <el-option label="收徒红包" value="4"></el-option>
                    <el-option label="提现" value="101"></el-option>
                    <el-option label="转发奖励" value="102"></el-option>
                  </el-select>
                </el-form-item>
     
                <el-form-item label="用户昵称/ID：">
                  <el-input v-model="formInline.name" placeholder="用户昵称/ID"></el-input>
                </el-form-item>
                
                <el-form-item>
                  <el-button type="primary" @click="onSubmit">查询</el-button>
                </el-form-item>
              </el-form>

              <el-table
                :data="tableData"
                border
                :cell-style="{'text-align':'center'}"
                :header-cell-style="{
                  'background-color': '#f5f5f5',
                  'color':'#555',
                  'text-align':'center'
                }"
                style="width: 100%">
                <el-table-column
                  prop="createdUserNickName"
                  label="昵称">
                  <template slot-scope="scope">
                    <el-button @click="checkClick(scope.row)" type="text" size="small">{{scope.row.createdUserNickName}}</el-button>
                  </template>
                </el-table-column>
                <el-table-column
                  prop="journalTyp"
                  :formatter="typeFormatter"
                  label="资金类型">
                </el-table-column>
                <el-table-column
                  prop="remark"
                  label="备注">
                </el-table-column>
                <el-table-column
                  prop="journalAmt"
                  label="金额（元）">
                </el-table-column>
                <el-table-column
                  prop="withdrawAmt"
                  label="可提金额（元）">
                </el-table-column>
  
                <el-table-column
                  prop="createdDate"
                  label="申请时间">
                </el-table-column>
 
                
              </el-table>
              <div class="block">
                <el-pagination
                  @size-change="handleSizeChange"
                  @current-change="handleCurrentChange"
                  :current-page="currentPage"
                  :page-sizes="[20, 50, 100]"
                  :page-size="pagesize"
                  layout="total, sizes, prev, pager, next, jumper"
                  :total="total">
                </el-pagination>
              </div>
    
            </div>

          </div>
        </el-main>
      </el-container>

    </el-container>
  </div>
</template>
<script>
import { getCookie,timeChange,getQueryString } from "./until/index";
function init(){
  this.$ajax.get("admGetCashJournalList.ashx?uid="+getCookie("userid") +"&token=" +getCookie("token")+'&journalType='+this.formInline.status+
        '&dateFrom='+this.startTime +
        '&dateTo='+this.endTime +
        '&nickName='+this.userID+
        '&ps='+this.pagesize+
        '&pi='+this.currentPage
      )
      .then(res => {
        if (res.data.code === "200") {
          var data = res.data.data;
          console.log(data)
          this.total = Number(data.rowCount)
          if(data.rowCount >0){

            this.tableData = data.cashList;
          }else{
            this.tableData = []
          }
          
        } else {
          this.$message.error(res.data.msg );
        }
      })
      .catch(error => {
        console.log(error);
      });
}
export default {
  data() {
    return {
      pagesize: 20, //每页显示条数
      currentPage: 1, //初始页
      total: 0, //总条数
      startTime:'',
      endTime:'',
      userID:'',
      formInline: {
        time:'',//查询时间
        name: '', //用户昵称/ID
        status:'',  //资金类型
      },
      tableData: [],

    };
  },
  created() {
    
    if(getQueryString()){

      this.userID = getQueryString();
      this.formInline.name = getQueryString()
    }
    init.call(this)
  },
  methods: {
    onSubmit() {
      if(this.formInline.time){

        this.startTime = timeChange(this.formInline.time[0])
        this.endTime = timeChange(this.formInline.time[1])
      }

      this.userID = this.formInline.name
      init.call(this)
    },
    checkClick(row){
      let routeUrl = this.$router.resolve({ path: '/index', query: { userID: row.createdUserID }});
      window.open(routeUrl .href, '_blank');
    },
    handleCurrentChange(num) {
      this.currentPage = num;
      init.call(this)
    },
    handleSizeChange(val) {
      this.pagesize = val;
      init.call(this)
    },
    typeFormatter(row){
      if(row.journalType == '0'){
        return '新人红包'
      }else if(row.journalType == '1'){
        return '定时红包'
      }else if(row.journalType =='2'){
        return '转发红包'
      }else if(row.journalType == '3'){
        return '瓜分红包'
      }else if(row.journalType == '4'){
        return '收徒红包'
      }else if(row.journalType == '101'){
        return '提现'
      }else if(row.journalType == '102'){
        return '转发奖励'
      }else{
        return row.journalType
      }
    }
  }
};
</script>
<style scoped>
.index {
  overflow: hidden;
}
.water{margin-right: 10px;display: inline-block}
.waterTime{font-size: 14px;color: #606266;padding: 0 12px 0 0;box-sizing: border-box;}
.el-header {
  background-color: #3a4759;
  color: #fff;
}
.el-aside {
  background-color: #485668;
  color: #333;
  text-align: center;
  line-height: 200px;
  overflow: hidden;
}
.el-main {
  background-color: #f0f2f5;
  color: #333;
  text-align: center;
  height: 100%;
  min-height: 740px
}

.header-top{
  margin: -20px -20px 20px;
  padding: 15px 20px;
  background: #fff;
  
}
.header-top .title{
  margin:15px 0 0;
  font-weight: 600;
  text-align: center;
  font-size: 18px;
}
.row{
  background: #fff;
  padding: 20px 30px;
  text-align: left
}
.block {
  padding: 20px;
}
.message{
  margin-top: 20px;
}
</style>
  